class DepartmentController < ApplicationController
  
  before_filter :verify_session
  
  def list
    @departments_pages, @departments = paginate :departments, :per_page => 10
     render :action => 'list'
  end
  
  def new
    @department = Department.new
  end
  
  def create
    @department = Department.new(params[:department])
    if @department.save
      redirect_to :action => 'list'
      else
      render :action => 'new'
    end
  end
  
  def destroy
    @department = Department.find(params[:id])
    if @department.destroy
      redirect_to :action => 'list'
      else
      render :action => 'list'
    end
  end
  
  def edit
    @department = Department.find(params[:id])
  end
  
  def update
    @department = Department.find(params[:id])
    if @department.update_attributes(params[:department])
      flash[:notice]='更新成功'
    else
      flash[:notice]='更新失败'
    end
    redirect_to :action=>'list'
  end
end
